﻿using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Volo.Abp.EntityFrameworkCore;
using System.IO;
using Microsoft.EntityFrameworkCore;

namespace WenABP.Customer.EntityFrameworkCore.Migration
{
    class CustomerDbContextMigrationFactory : IDesignTimeDbContextFactory<CustomerDbMigrationContext>
    {
        public CustomerDbMigrationContext CreateDbContext(string[] args)
        {
            var configuration  = BuildConfiguration();
            string connString = configuration.GetConnectionString("CustomerConnString");
            var builder = new DbContextOptionsBuilder<CustomerDbMigrationContext>()
                .UseMySql(connString, ServerVersion.AutoDetect(connString));
            return new CustomerDbMigrationContext(builder.Options);
        }

        private static IConfigurationRoot BuildConfiguration()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false);
            return builder.Build();
        }
    }
}
